package com.artifact.mit.mypoint.activity;

import static com.artifact.mit.mypoint.util.Variable.PREFS_NAME;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.view.Window;

import com.artifact.mit.mypoint.R;

public class SplashScreen extends Activity {

	private static final int DISPLAY_INTERVAL = 2000;

	private Handler splashHandler;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.splash_screen);

		splashHandler = new Handler();
		splashHandler.postDelayed(new Runnable() {
			@Override
			public void run() {
				SharedPreferences preferences = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
				Intent intent = null;
				if (!"".equals(preferences.getString("id", ""))) {
					intent = new Intent(SplashScreen.this, MainActivity.class);
				} else {
					intent = new Intent(SplashScreen.this, LoginActivity.class);
				}
				startActivity(intent);
				finish();
			}
		}, DISPLAY_INTERVAL);
	}
}
